import Vue from 'vue';
import Vuex from 'vuex';
import Player from '../lib/Player.js'
Vue.use(Vuex);

export default new Vuex.Store({
	state: {
		player1: null,
		player2: null,
		player3: null,
		players: {},
		landLordCards:'',
		gameStart:false,
		currentScore: 0,
		isChooseLandlord: true
	},
	mutations: {
		setProps(state, obj) {
			state[obj.key] = obj.value;
		},
		setPlayersProps(state, obj) {
			if (!obj.prop) {
				delete state.players[obj.key];
				if(state.player1&&state.player1.id==obj.key){
					state.player1 = null;
				}else if(state.player2&&state.player2.id==obj.key){
					state.player2 = null;
				}else if(state.player3&&state.player3.id==obj.key){
					state.player3 = null;
				}
				return;
			}
			if (!state.players[obj.key]) state.players[obj.key] = new Player(obj.key);
			state.players[obj.key][obj.prop] = obj.value;
			// if(state.player1&&state.player1.id==obj.key){
			// 	state.player1 = state.players[obj.key];
				
			// }else if(state.player2&&state.player2.id==obj.key){
			// 	state.player2 = state.players[obj.key];
			// }else if(state.player3&&state.player3.id==obj.key){
			// 	state.player3 = state.players[obj.key];
			// }
		},
		setPlayerProp(state, obj) {
			if (!obj.prop) {
				state[obj.player] = null;
				return;
			}
			// if (!state[obj.player]) state[obj.player] = new Player();
			state[obj.player][obj.prop] = obj.value;
			state[obj.player]['key'] = obj.player;
		}
	},
	actions: {}
})
